<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items">
                <el-menu-item :index="item.index" :key="item.index">
                    <i :class="item.icon"></i>
                    <span slot="title">{{ item.title }}</span>
                </el-menu-item>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from '../common/bus';
export default {
    data() {
        return {
            collapse: false,
            items: [
                {
                    icon: 'el-icon-lx-home',
                    index: 'dashboard',
                    title: '系统首页',
                    role: 'all'
                },
                {
                    icon: 'el-icon-lx-cascades',
                    index: 'region', //路由地址
                    title: '区域信息',
                    role: 'President;VP, Administration;VP, Finance;VP, Operations;VP, Sales'
                },
                {
                    icon: 'el-icon-lx-copy',
                    index: 'dept',
                    title: '部门信息',
                    role: 'President;VP, Administration;VP, Finance;VP, Operations;VP, Sales'
                },
                {
                    icon: 'el-icon-lx-calendar',
                    index: 'title',
                    title: '职称信息',
                    role: 'President;VP, Administration;VP, Finance;VP, Operations;VP, Sales'
                },
                {
                    icon: 'el-icon-lx-emoji',
                    index: 'emp',
                    title: '员工信息',
                    role: 'President;VP, Administration;VP, Finance;VP, Operations;VP, Sales;Warehouse Manager'
                },
                {
                    icon: 'el-icon-pie-chart',
                    index: 'cus',
                    title: '客户信息',
                    role: 'President;Sales Representative;VP, Administration;VP, Finance;VP, Operations;VP, Sales'
                },
                // {
                //     icon: 'el-icon-rank',
                //     index: '6',
                //     title: '仓库信息',
                //     role: 'President;Stock Clerk;VP, Administration;VP, Finance;VP, Operations;VP, Sales;Warehouse Manager'
                // },
                // {
                //     icon: 'el-icon-lx-global',
                //     index: 'i18n',
                //     title: '库存信息',
                //     role : 'President;Stock Clerk;VP, Administration;VP, Finance;VP, Operations;VP, Sales;Warehouse Manager'
                // },
               {
                    icon: 'el-icon-lx-redpacket_fill',
                    index: 'product',
                    title: '商品信息',
                    role : 'all'
                },
                {
                    icon: 'el-icon-lx-warn',
                    index: 'order',
                    title: '订单信息',
                    role: 'President;Sales Representative;VP, Administration;VP, Finance;VP, Operations;VP, Sales'
                },
            ]
        };
    },
    methods: {
        judge(role){
            if(role){
                if(role==="all"){
                    return true;
                }
                let title = localStorage.getItem("title");//已经登录用户的角色。
                return role.indexOf(title)!=-1;
            }
            return false;
        }
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', (msg) => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
